Skip to content

fix: use merge-base anchors for stale branch adoption#38

Merged
roodboi merged 2 commits into
mainfrom
fix-track-stale-adoption-anchor
Mar 26, 2026
Merged

fix: use merge-base anchors for stale branch adoption#38
roodboi merged 2 commits into
mainfrom
fix-track-stale-adoption-anchor

Conversation

@roodboi

@roodboi roodboi commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

Summary

  • fix HACK-615 by deriving track restack anchors from real shared history when a parent has moved
  • keep strict invalid-anchor restack behavior while making stale existing PR adoption repairable
  • document the supported stale-adoption flow in the usage and adoption guides

Verification

  • mise exec -- go test ./...
  • mise exec -- go build ./...
  • manual temp-repo repro of stale adoption: track stale child, run stack restack --all, confirm the stored anchor moves from old parent base to new parent head

Fix HACK-615 by teaching stack track to record a repairable restack anchor when adopting a branch whose parent has already moved. If the current parent tip is not an ancestor, track now stores the merge-base instead of unusable metadata.
@linear

linear Bot commented Mar 26, 2026

Copy link
Copy Markdown

HACK-615

@roodboi roodboi merged commit 97fbc5c into main Mar 26, 2026
2 checks passed
@roodboi roodboi deleted the fix-track-stale-adoption-anchor branch March 26, 2026 02:20

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c5d68c227c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/cmd/root.go
Comment on lines +1375 to +1379
if !ok || mergeBase == "" {
return "", fmt.Errorf("branch %q does not share a repairable merge base with parent %q; rebase it first or choose a different parent", branch, parent)
}

return mergeBase, nil

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reject unsafe merge-base anchors for rebased parents

trackRestackAnchor currently accepts any git merge-base(parent, branch) result as a repairable anchor and stores it in LastParentHeadOID, but that is unsafe when the parent was rebased/force-pushed: the merge base may fall back to trunk, and runRestackPlan later calls git rebase --onto <parent> <anchor> <branch>, which replays old parent-only commits onto the child (not just child commits). This changes prior behavior from a hard stop on invalid anchors to silent history corruption in stale-adoption flows where the parent history was rewritten, so this fallback needs an additional safety check (or explicit refusal) before accepting the merge-base anchor.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant